package cn.lijiajia3515.cairo.captcha.image;

import cn.lijiajia3515.cairo.captcha.CaptchaArgs;
import cn.lijiajia3515.cairo.captcha.code.CodeCaptcha;
import cn.lijiajia3515.cairo.captcha.code.CodeCaptchaHandler;
import cn.lijiajia3515.cairo.captcha.image.graph.GraphImageHandler;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

public class CodeImageCaptchaHandler extends ImageCaptchaHandler {

	private final CodeCaptchaHandler codeCaptchaHandler;

	public CodeImageCaptchaHandler(CodeCaptchaHandler codeCaptchaHandler) {
		this.codeCaptchaHandler = codeCaptchaHandler;
	}

	public CodeImageCaptchaHandler(CodeCaptchaHandler codeCaptchaHandler, GraphImageHandler graphImageHandler) {
		super(graphImageHandler);
		this.codeCaptchaHandler = codeCaptchaHandler;
	}

	@Override
	protected Tuple2<String, String> getImageCaptchaStr(CaptchaArgs args) {
		CodeCaptcha captcha = codeCaptchaHandler.getCaptcha(args);
		return Tuples.of(captcha.getCode(), captcha.getCode());
	}

	public enum Singleton {
		NUM(new CodeImageCaptchaHandler(CodeCaptchaHandler.Singleton.NUM.handler)),
		CHAR(new CodeImageCaptchaHandler(CodeCaptchaHandler.Singleton.CHAR.handler)),
		UPPER_CHAR(new CodeImageCaptchaHandler(CodeCaptchaHandler.Singleton.UPPER_CHAR.handler)),
		LOWER_CHAR(new CodeImageCaptchaHandler(CodeCaptchaHandler.Singleton.LOWER_CHAR.handler)),
		CHINESE(new CodeImageCaptchaHandler(CodeCaptchaHandler.Singleton.CHINESE.handler));

		public final CodeImageCaptchaHandler handler;

		Singleton(CodeImageCaptchaHandler handler) {
			this.handler = handler;
		}
	}


}
